package com.beecloud.microservice.user.commom;

import com.beecloud.microservice.user.domain.dto.Page;

public class PageUtils {
    public static boolean invalidPage(int page) {
        return !positiveNum(page);
    }

    public static boolean invalidPageSize(int pageSize) {
        return  !positiveNum(pageSize);
    }

    public static int totalPage(int totalCount, int pageSize) {
        return (totalCount + pageSize - 1) / pageSize;
    }

    public static  boolean hasNextPage(int page, int pageSize, int totalCount) {
        return (page - 1) * pageSize < totalCount;
    }

    public static <T> void fullPageMeta(int page, int pageSize, int totalSize, Page<T> p) {
        p.setPageNo(page);
        p.setPageSize(pageSize);
        p.setTotalSize(totalSize);
        p.setTotalPage(totalPage(totalSize, pageSize));
    }

    private static boolean positiveNum(int target) {
        return target>0 && target< Integer.MAX_VALUE;
    }

}
